package com.softer.wxzj.controller;

import com.github.pagehelper.PageInfo;
import com.softer.wxzj.common.aop.annotation.LogRecord;
import com.softer.wxzj.common.aop.enums.LogOperationType;
import com.softer.wxzj.common.aop.enums.LogOperationUnit;
import com.softer.wxzj.common.entity.CommonResult;
import com.softer.wxzj.common.entity.Page;
import com.softer.wxzj.entity.*;
import com.softer.wxzj.service.ExpProjectReqAuditService;
import com.softer.wxzj.service.ExpProjectReqService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author Gong Zhiyang
 * @date 2019/7/17
 */
@RestController
@RequestMapping("/expProjectReq")
public class ExpProjectReqController {
    @Autowired
    private ExpProjectReqService expProjectReqService;
    @Autowired
    private ExpProjectReqAuditService expProjectReqAuditService;

    /**
     * 获取项目管理列表
     *
     * @param page           分页实体
     * @param baseRegionInfo 查询实体
     * @return 列表
     */
    @PostMapping("/getRegionList")
    @LogRecord(description = "获取项目管理列表", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<BaseRegionInfo> getRegionList(Page page, BaseRegionInfo baseRegionInfo) {
        return expProjectReqService.getRegionList(page, baseRegionInfo);
    }

    /**
     * 预览
     *
     * @param page          分页实体
     * @param expProjectReq 查询实体
     * @return 列表
     */
    @PostMapping("/preview")
    @LogRecord(description = "预览", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<ExpProjectReq> preview(Page page, ExpProjectReq expProjectReq) {
        return expProjectReqService.preview(page, expProjectReq);
    }

    /**
     * 业委会/居委会维修项目管理列表
     *
     * @param page          分页实体
     * @param expProjectReq 查询实体
     * @return 列表
     */
    @PostMapping("/previewForCommittee")
    @LogRecord(description = "业委会/居委会维修项目管理列表", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<ExpProjectReq> previewForCommittee(Page page, ExpProjectReq expProjectReq) {
        return expProjectReqService.previewForCommittee(page, expProjectReq);
    }


    @RequestMapping("/getExpirationDate")
    public PageInfo<ExpProjectReq> getExpirationDate(Page page, String regionId, String maintainType) {
        return expProjectReqService.getExpirationDate(page, regionId, maintainType);
    }

    /**
     * 页签展示标记与申报按钮展示标记
     *
     * @param expProjectReq
     * @return
     */
    @RequestMapping("/whetherAllowDeclaration")
    @LogRecord(description = "页签展示标记与申报按钮展示标记", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public TabAndDeclareEntity whetherAllowDeclaration(ExpProjectReq expProjectReq) {
        return expProjectReqService.whetherAllowDeclaration(expProjectReq);
    }

    /**
     * 维修项目新增
     *
     * @return 结果
     */
    @PostMapping("/add")
    @LogRecord(description = "维修项目新增", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.INSERT)
    public CommonResult addSave(@RequestBody ReqList reqList) {
        return expProjectReqService.addSave(reqList);
    }

    /**
     * 申报
     *
     * @param id 项目ID
     * @return 修改结果
     */
    @PostMapping("/updateState")
    @LogRecord(description = "申报", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.UPDATE)
    public CommonResult updateState(String id, String proReportUser) {
        return expProjectReqService.updateState(id, proReportUser);
    }

    /**
     * 批量申报
     *
     * @param list 项目Id集合
     * @return 修改结果
     */
    @PostMapping("/batchCommit")
    @LogRecord(description = "批量申报", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.UPDATE)
    public CommonResult batchCommit(@RequestBody List<String> list) {
        return expProjectReqService.batchCommit(list);
    }

    /**
     * 外网批量申报
     *
     * @param reqList list 项目Id集合
     *                operNo 登录账号
     * @return 修改结果
     */
    @PostMapping("/batchCommitFromExtraNet")
    @LogRecord(description = "外网批量申报", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.UPDATE)
    public CommonResult batchCommitFromExtraNet(@RequestBody ReqList reqList) {
        return expProjectReqService.batchCommitFromExtraNet(reqList);
    }

    /**
     * 修改
     *
     * @param reqList 维修项目
     * @return 结果
     */
    @PostMapping("/update")
    @LogRecord(description = "维修项目修改", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.UPDATE)
    public CommonResult update(@RequestBody ReqList reqList) {
        return expProjectReqService.update(reqList);
    }

    /**
     * 查詢详情
     *
     * @param id ID
     * @return 维修项目
     */
    @PostMapping("/getInfo")
    @LogRecord(description = "查詢维修项目详情", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public ExpProjectReq getInfo(String id) {
        return expProjectReqService.getInfo(id);
    }

    /**
     * 查詢详情
     * 用于跳转连接的查询
     *
     * @param id ID
     * @return 维修项目
     */
    @PostMapping("/getDetails")
    @LogRecord(description = "查詢维修项目详情", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public ExpProjectReq getDetails(String id) {
        return expProjectReqService.getDetails(id);
    }

    /**
     * 刪除
     *
     * @param id ID
     * @return 結果
     */
    @PostMapping("/delete")
    @LogRecord(description = "刪除维修项目", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.DELETE)
    public CommonResult delete(String id) {
        return expProjectReqService.delete(id);
    }

    /**
     * 竣工验收列表
     *
     * @param page          分页实体
     * @param expProjectReq 查询实体
     * @return 列表
     */
    @PostMapping("/finish")
    @LogRecord(description = "竣工验收列表", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<ExpProjectReq> finish(Page page, ExpProjectReq expProjectReq) {
        return expProjectReqService.finish(page, expProjectReq);
    }

    /**
     * 验收决算金额最大可输入上限
     *
     * @param id 项目id
     * @return
     */
    @PostMapping("/inputFinishNumMax")
    @LogRecord(description = "验收决算金额最大可输入上限", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public BigDecimal inputFinishNumMax(String id) {
        return expProjectReqService.inputFinishNumMax(id);
    }

    /**
     * 验收详情查询
     *
     * @param id      项目id
     * @param arcType 图档大类
     * @return 详情查询
     */
    @PostMapping("/getFinishInfo")
    @LogRecord(description = "验收详情查询", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public ExpProjectReq getFinishInfo(String id, String arcType) {
        return expProjectReqService.getFinishInfo(id, arcType);
    }

    /**
     * 项目验收
     *
     * @param expProjectReq 验收项目实体
     * @return 操作结果
     */
    @PostMapping("/updateFinish")
    @LogRecord(description = "项目验收", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.UPDATE)
    public CommonResult updateFinish(@RequestBody ExpProjectReq expProjectReq) {
        return expProjectReqService.updateFinish(expProjectReq);
    }

    /**
     * 验收撤销
     *
     * @param id      项目id
     * @param arcType 图档大类
     * @param operNo  外网操作账号
     * @return 撤销结果
     */
    @PostMapping("/finishCancel")
    @LogRecord(description = "验收撤销", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.UPDATE)
    public CommonResult finishCancel(String id, String arcType, String operNo) {
        return expProjectReqService.finishCancel(id, arcType, operNo);
    }

    /**
     * 项目审核
     *
     * @param businessId 项目ID
     * @param mark       状态（1同意，0不同意）
     * @param opinion    审核意见
     * @param proDate    审核日期
     * @param operNo     外网审核时使用
     * @return 操作结果
     */
    @PostMapping("/audit")
    @LogRecord(description = "项目审核", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.UPDATE)
    public CommonResult audit(String businessId, String opinion, String mark, String proDate, String operNo) {
        return expProjectReqAuditService.audit(businessId, opinion, mark, proDate, operNo);
    }

    /**
     * 项目审批列表
     *
     * @param page  分页实体
     * @param fuzzy 模糊字段
     * @return 列表
     */
    @RequestMapping("/getAuditSearchList")
    @LogRecord(description = "项目审批列表", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<ExpProjectReq> getAuditSearchList(Page page, String fuzzy) {
        return expProjectReqAuditService.getAuditSearchList(page, fuzzy);
    }

    /**
     * 外网查询应急项目审批列表
     *
     * @param page          分页实体
     * @param expProjectReq 查询实体
     * @return 列表
     */
    @RequestMapping("/getEmergencyAuditSearchList")
    @LogRecord(description = "外网查询应急项目审批列表", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<ExpProjectReq> getEmergencyAuditSearchList(Page page, ExpProjectReq expProjectReq) {
        return expProjectReqAuditService.getEmergencyAuditSearchList(page, expProjectReq);
    }

    /**
     * 项目审核意见查询
     *
     * @param businessId 审核ID
     * @return 操作结果
     */
    @RequestMapping("/getCurrentAuditdetailList")
    @LogRecord(description = "项目审核意见查询", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public List<FlowAuditdetail> getCurrentAuditdetailList(String businessId) {
        return expProjectReqAuditService.getCurrentAuditdetailList(businessId);
    }

    /**
     * 查询当前小区选中的维修类别下的维修对象信息
     *
     * @param maintenanceEquipment regionId            小区id&
     *                             maintenanceObjectId 对象类别ID
     *                             subRegionId 分区ID
     *                             buildId 自然幢ID
     *                             splitRange 分摊范围
     * @return 维修对象信息
     */
    @RequestMapping("/selectMaintenanceEquipment")
    @LogRecord(description = "查询当前小区选中的维修类别下的维修对象信息", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public List<MaintenanceEquipment> selectMaintenanceEquipment(MaintenanceEquipment maintenanceEquipment) {
        return expProjectReqService.selectMaintenanceEquipment(maintenanceEquipment);
    }

    /**
     * 新增分摊保存
     *
     * @param reqList OwnerSignatureList  业主详情集合
     *                ExpProjectReq 项目实体
     * @return 新增结果
     */
    @RequestMapping("/apportionInfoSave")
    @LogRecord(description = "新增分摊保存", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.INSERT)
    public CommonResult apportionInfoSave(@RequestBody ReqList reqList) {
        return expProjectReqService.apportionInfoSave(reqList.getExpProjectReq(), reqList.getOwnerSignatureList());
    }

    /**
     * 新增分摊明细
     *
     * @param reqList list  分摊ID集合
     *                *           reqId 项目ID
     * @return 分摊详情
     */
    @RequestMapping("/apportionDetail")
    @LogRecord(description = "新增分摊明细", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.INSERT)
    public Map<String, Object> apportionDetail(@RequestBody ReqList reqList) {
        return expProjectReqService.apportionDetail(reqList.getList(), reqList.getReqId());
    }

    /**
     * 分摊划分
     *
     * @param id 项目ID
     * @return 所有自然幢
     */
    @PostMapping("/getApportionInfo")
    @LogRecord(description = "分摊划分", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public Map<String, List<BaseBuildInfo>> getApportionInfo(String id) {
        return expProjectReqService.getApportionInfo(id);
    }

    /**
     * 查询自然幢汇总信息，用于分摊划分时的自然幢浮窗显示
     *
     * @param id 自然幢Id
     * @return 汇总信息
     */
    @PostMapping("/getBuildSummaryInfo")
    @LogRecord(description = "查询自然幢汇总信息", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public BuildSummaryInfo getBuildSummaryInfo(String id) {
        return expProjectReqService.getBuildSummaryInfo(id);
    }

    /**
     * 预分摊清册
     *
     * @param reqId 项目ID
     * @return 分摊详情
     */
    @RequestMapping("/apportionform")
    @LogRecord(description = "预分摊清册", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<OwnerSignature> apportionForm(String reqId, Page page) {
        return expProjectReqService.apportionForm(reqId, page);
    }

    /**
     * 获取使用申请表数据信息
     *
     * @param id 项目ID
     * @return 申请表数据
     */
    @PostMapping("/getApplication")
    @LogRecord(description = "获取使用申请表数据信息", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public Application getApplication(String id) {
        return expProjectReqService.getApplication(id);
    }

    /**
     * 查询房间使用项目列表
     *
     * @param expProjectReq 查询实体
     * @return 项目列表
     */
    @PostMapping("/selectByHouseId")
    @LogRecord(description = "查询房间使用项目列表", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<ExpProjectReq> selectByHouseId(Page page, ExpProjectReq expProjectReq) {

        return expProjectReqService.selectByHouseId(page, expProjectReq);
    }

    /**
     * 通过维修项目查询项目
     *
     * @param page
     * @return
     */
    @PostMapping("/selectByMainObject")
    @LogRecord(description = "通过维修项目查询项目", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<ExpProjectReq> selectByMainObject(Page page, ExpProjectReq expProjectReq) {
        return expProjectReqService.selectByMainObject(page, expProjectReq);

    }

    /**
     * 通过维修企业、审计企业、监理企业查询维修项目的接口
     *
     * @param page          分页实体
     * @param expProjectReq 查询实体
     * @return 维修项目列表
     */
    @PostMapping("/getProjectReqListByCorpId")
    @LogRecord(description = "通过维修企业、审计企业、监理企业查询维修项目", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<ExpProjectReq> getProjectReqListByCorpId(Page page, ExpProjectReq expProjectReq) {
        return expProjectReqService.getProjectReqListByCorpId(page, expProjectReq);
    }

    /**
     * 查询自然幢维修记录列表
     *
     * @param page    分页实体
     * @param buildId 自然幢ID
     * @return 列表
     */
    @PostMapping("/getBuildProjectList")
    @LogRecord(description = "查询自然幢维修记录列表", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<ExpProjectReq> getBuildProjectList(Page page, String buildId) {
        return expProjectReqService.getBuildProjectList(page, buildId);
    }

    /**
     * 项目审核查询列表
     *
     * @param page
     * @param expProjectReq
     * @return
     */
    @PostMapping("/projectCheckList")
    @LogRecord(description = "项目审核查询列表", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<ExpProjectReq> projectCheckList(Page page, ExpProjectReq expProjectReq, String operNo) {
        return expProjectReqService.projectCheckList(page, expProjectReq, operNo);
    }

    /**
     * 业委会/居委会项目审核查询列表
     *
     * @param page          分页实体
     * @param expProjectReq 查询实体
     * @return 项目审核查询列表
     */
    @PostMapping("/projectCheckListForCommittee")
    @LogRecord(description = "业委会/居委会项目审核查询列表", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<ExpProjectReq> projectCheckListForCommittee(Page page, ExpProjectReq expProjectReq) {
        return expProjectReqService.projectCheckListForCommittee(page, expProjectReq);
    }

    /**
     * 业委会/居委会拨款审核查询列表
     *
     * @param page          分页实体
     * @param expProjectReq 查询实体
     * @return 拨款审核查询列表
     */
    @PostMapping("/appropriationCheckListForCommittee")
    @LogRecord(description = "业委会/居委会拨款审核查询列表", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<ExpProjectReq> appropriationCheckListForCommittee(Page page, ExpProjectReq expProjectReq) {
        return expProjectReqService.appropriationCheckListForCommittee(page, expProjectReq);
    }

    /**
     * 拨款审核查询列表
     *
     * @param page
     * @param expProjectReq
     * @return
     */
    @PostMapping("/appropriationCheckList")
    @LogRecord(description = "拨款审核查询列表", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.SELECT)
    public PageInfo<ExpProjectReq> appropriationCheckList(Page page, ExpProjectReq expProjectReq) {
        return expProjectReqService.appropriationCheckList(page, expProjectReq);
    }


    /**
     * 分摊划分重置
     *
     * @param reqId 项目ID
     * @return 分摊划分重置结果
     */
    @PostMapping("/reset")
    @LogRecord(description = "分摊划分重置", operationUnit = LogOperationUnit.EXP_PROJECT_REQ, operationType = LogOperationType.UPDATE)
    public CommonResult reset(String reqId) {
        return expProjectReqService.reset(reqId);
    }

}
